package com.coocare.licence.config.auth;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 *
 * @author adam
 * @create 2023/5/25 14:30
 */

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    /**
     * 注册拦截器
     *
     * @param registry
     */
    @Override
    @SneakyThrows
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns("/login",
                        "/swagger-resources/**", "/webjars/**","/captcha/**", "/**/api-docs/**",
                        "/swagger-ui.html/**", "/doc.html", "/auth/**", "/rest/**", "/static/**", "/favicon.ico");
    }
}
